<template>
  <div class="search">
    
      <el-row :gutter="15">
        <el-form ref="elForm" :model="queryParams"  size="medium" label-width="120px">
          <el-col :span="50">
            <el-row :gutter="30">
              <el-col :span="10">
                <el-form-item label="销售开票号码:"  prop = "purchaser">
                      <el-autocomplete
                        v-model="queryParams.salesInvoiceNumber"
                        :fetch-suggestions="querySearchAsync5"
                        placeholder="请输入内容"
                        @select="handleSelect5"
                        @input="Changed($event)"
                        input="text()"
                        @blur="getQueryFrom()"
                        @clear="resetForm('purchaseName')"
                        clearable
                        >
                        <template slot-scope="{ item }">
                          <div class="name">{{ item.value }}</div>
                          <span class="addr">{{ item.address }}</span>
                        </template>
                      </el-autocomplete>
                    </el-form-item>
              </el-col>
              
              <el-col :span="10">
                  <el-form-item  label="销售日期:" label-width="120px">
                    <el-date-picker
                      v-model="queryParams.salesDate"
                      align="right"
                      type="date"
                      @blur="getQueryFrom()"
                      value-format="yyyy-MM-dd"
                      placeholder="选择日期"
                      :picker-options="pickerOptions">
                    </el-date-picker>
                  </el-form-item>
              </el-col>
              <el-col  :span="4">
              <el-button @click="resetForm()" >重置</el-button>
              </el-col>
              
            </el-row>
            <el-row>
              <el-col :span="10">
                <el-form-item label="销售订单号:" prop="field108" label-width="120px">
                  <el-autocomplete
                    v-model="queryParams.salesOrderNumber"
                    :fetch-suggestions="querySearchAsync7"
                    placeholder="请输入订单号"
                    @select="handleSelect7"
                    @clear="getQueryFrom()"
                    @blur="getQueryFrom()"
                    clearable
                    >
                    <template slot-scope="{ item }">
                          <div class="name">{{ item.value }}</div>
                          <span class="addr">{{ item.address }}</span>
                        </template>
                  </el-autocomplete>
                </el-form-item>
              </el-col>
              
              <el-col :span="10">
                
              </el-col>
            </el-row>
            
          </el-col>
          
        </el-form>

      </el-row>
     
      <div class = "infotable">
        <!-- 操作按钮 -->
        <div class = "infotable_handerchild">
          <el-button  type="primary" @click="addHanderPop = true">新增</el-button>
          <el-button  type="primary" :disabled="editBotton" @click="editPop()">修改</el-button>

          <el-button type="danger" :disabled="deleteBotton" @click="deletetable()">删除</el-button>
          <el-button type="info" @click="upload.open=true">导入</el-button>
          <el-button type="info"  @click="importData()">导出</el-button>

          <el-button  type="primary" :disabled="editBotton" @click="">开票</el-button>
        </div>
        <div class = "infotable_handerchild"  style = "min-height:600px ;">
          <el-table
          ref="multipleTable"
          max-height="600"
          tooltip-effect="dark"
          @selection-change="handleSelectionChange"
          :data="tableData"
          style="width: 100%">
          
          
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          
          <el-table-column
          prop="salesOrderNumber"
          label="销售订单号">
          </el-table-column>
          <el-table-column
          prop="salesDeliveryDate"
          label="销售货期"
          width="80">
          </el-table-column>
          <el-table-column
          prop="salesDate"
          label="销售日期"
          width="160">
          </el-table-column>
          <el-table-column
          prop="customerName"
          label="客户名称"
          width="120">
          </el-table-column>
          <el-table-column
          prop="salesInvoiceNumber"
          label="销售开票号码"
          width="100">
          </el-table-column>
          <el-table-column
          prop="salesInvoiceDate"
          label="销售开票日期">
          </el-table-column>
          <el-table-column
          prop="salesInvoiceQuantity"
          label="销售开票数量">
          </el-table-column>
          <el-table-column
          prop="salesInvoiceAmount"
          label="销售开票金额">
          </el-table-column>
          <el-table-column
          prop="unpaidSalesInvoiceAmount"
          label="销售未开票金额">
          </el-table-column>
          <el-table-column
          prop="salesCost"
          label="销售成本">
          </el-table-column>
          <el-table-column
            prop="remarks"
            label="备注"
            width="300"
            style="height: 50px;">
          </el-table-column>
         
          
        </el-table>
        
                <!-- 新增弹框 -->
                <el-dialog class="HanderPop" title="新增销售批次" :visible.sync="addHanderPop" >
                   
                  <el-form :model="form" :rules="rules" ref="form" :inline="true" label-position="right">
                    
                  
                    <el-form-item label="销售订单号" :label-width="formLabelWidth"  prop="quantity">
                      <el-input class="inputplace" 
                      v-model="form.salesOrderNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="销售货期" :label-width="formLabelWidth" prop="unit">
                      <el-input class="inputplace" 
                      v-model="form.salesDeliveryDate"></el-input>
                    </el-form-item>
                    <el-form-item label="销售日期" :label-width="formLabelWidth" prop="orderNumberProduct" >
                      <el-date-picker
                        v-model="form.salesDate"
                        align="right"
                        type="date"
                        placeholder="选择日期"
                        :picker-options="pickerOptionsdate">
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item label="客户名称" :label-width="formLabelWidth"  prop="unitPrice">
                      <el-input class="inputplace" 
                      v-model="form.customerName"></el-input>
                    </el-form-item>
                    <el-form-item label="销售开票号码" :label-width="formLabelWidth"  prop="amount">
                      <el-input class="inputplace" 
                      v-model="form.salesInvoiceNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="销售开票日期" :label-width="formLabelWidth"  prop="taxIncludedPrice">
                      <el-date-picker
                        v-model="form.salesInvoiceDate"
                        align="right"
                        type="date"
                        placeholder="选择日期"
                        :picker-options="pickerOptionsdate">
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item label="销售开票数量" :label-width="formLabelWidth"  prop="totalPrice">
                      <el-input class="inputplace" 
                      v-model="form.salesInvoiceQuantity"></el-input>
                    </el-form-item>
                    <el-form-item label="销售开票金额" :label-width="formLabelWidth"   prop="paymentVoucher">
                      <el-input class="inputplace" 
                      v-model="form.salesInvoiceAmount"></el-input>
                    </el-form-item>
                    <el-form-item label="销售未开票金额" :label-width="formLabelWidth"  prop="paymentDate">
                      <el-input class="inputplace" 
                      v-model="form.unpaidSalesInvoiceAmount"></el-input>
                    </el-form-item>
                    <el-form-item label="销售成本" :label-width="formLabelWidth"  prop="paymentDate">
                      <el-input class="inputplace" 
                      v-model="form.salesCost"></el-input>
                    </el-form-item>
                    <el-form-item label="备注" :label-width="formLabelWidth"   prop="paymentAmount">
                      <el-input class="inputplace" 
                      v-model="form.remarks"></el-input>
                    </el-form-item>
                    
                  </el-form>
                  <div slot="footer" class="dialog-footer">
                    <el-button @click="addHanderPop = false">取 消</el-button>
                    <el-button type="primary" @click="addtable('form')">确 定</el-button>
                  </div>
                  </el-dialog>  


                 

                  <!-- 修改 -->
              
               <el-dialog class="HanderPop" title="修改销售批次" :visible.sync="editHanderPop" >
                   <el-form :model="editform" :rules="rules" ref="editform" :inline="true" label-position="right">
                    
                    <el-form-item label="销售订单号" :label-width="formLabelWidth"  prop="quantity">
                      <el-input class="inputplace" 
                      v-model="editform.salesOrderNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="销售货期" :label-width="formLabelWidth" prop="unit">
                      <el-input class="inputplace" 
                      v-model="editform.salesDeliveryDate"></el-input>
                    </el-form-item>
                    <el-form-item label="销售日期" :label-width="formLabelWidth" prop="orderNumberProduct" >
                      <el-date-picker
                        v-model="editform.salesDate"
                        align="right"
                        type="date"
                        placeholder="选择日期"
                        :picker-options="pickerOptionsdate">
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item label="客户名称" :label-width="formLabelWidth"  prop="unitPrice">
                      <el-input class="inputplace" 
                      v-model="editform.customerName"></el-input>
                    </el-form-item>
                    <el-form-item label="销售开票号码" :label-width="formLabelWidth"  prop="amount">
                      <el-input class="inputplace" 
                      v-model="editform.salesInvoiceNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="销售开票日期" :label-width="formLabelWidth"  prop="taxIncludedPrice">
                      <el-date-picker
                        v-model="form.salesInvoiceDate"
                        align="right"
                        type="date"
                        placeholder="选择日期"
                        :picker-options="pickerOptionsdate">
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item label="销售开票数量" :label-width="formLabelWidth"  prop="totalPrice">
                      <el-input class="inputplace" 
                      v-model="editform.salesInvoiceQuantity"></el-input>
                    </el-form-item>
                    <el-form-item label="销售开票金额" :label-width="formLabelWidth"   prop="paymentVoucher">
                      <el-input class="inputplace" 
                      v-model="editform.salesInvoiceAmount"></el-input>
                    </el-form-item>
                    <el-form-item label="销售未开票金额" :label-width="formLabelWidth"  prop="paymentDate">
                      <el-input class="inputplace" 
                      v-model="editform.unpaidSalesInvoiceAmount"></el-input>
                    </el-form-item>
                    <el-form-item label="销售成本" :label-width="formLabelWidth"  prop="paymentDate">
                      <el-input class="inputplace" 
                      v-model="editform.salesCost"></el-input>
                    </el-form-item>
                    <el-form-item label="备注" :label-width="formLabelWidth"   prop="paymentAmount">
                      <el-input class="inputplace" 
                      v-model="editform.remarks"></el-input>
                    </el-form-item>
                  </el-form>
                   <div slot="footer" class="dialog-footer">
                     <el-button @click="editHanderPop = false">取 消</el-button>
                     <el-button type="primary" @click="edittable('editform')">确 定</el-button>
                   </div>
                   </el-dialog>  
                  
                  




                 <!-- 导入对话框 -->
                    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
                      <el-upload
                        ref="upload"
                        :limit="1"
                        accept=".xlsx, .xls"
                        :headers="upload.headers"
                        :action="upload.url"
                        :disabled="upload.isUploading"
                        :on-progress="handleFileUploadProgress"
                        :on-success="handleFileSuccess"
                        :auto-upload="false"
                        drag
                      >
                        <i class="el-icon-upload"></i>
                        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                        <div class="el-upload__tip text-center" slot="tip">
                         
                          <span>仅允许导入xls、xlsx格式文件。</span>
                          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate()">下载模板</el-link>
                        </div>
                      </el-upload>
                      <div slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="submitFileForm()">确 定</el-button>
                        <el-button @click="upload.open = false">取 消</el-button>
                      </div>
                    </el-dialog>
        </div>
        
      </div>
      <el-footer>
        <!-- 分页 -->
        <div class="pagination">
        <el-pagination
         
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryParams.pageNum"
          :page-sizes="[10, 20, 30, 50]"   
          :page-size="queryParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="countNum"
          > <!--分页Size   最大页数-->
        </el-pagination>
      </div>
      </el-footer>
  </div>
</template>





















<script>
import { getSalesOrderList,getSalesOrderid,getAllSalesOrder,getSalesOrderInsert,getSalesOrderEdit,getSalesOrderDelete,getSalesOrderCount} from "@/api/finance/SalesOrder/SalesOrder";
import { getPurchaseBatchList,getPurchaseBatchid,getAllPurchaseBatch,getPurchaseBatchInsert,getPurchaseBatchEdit,getPurchaseBatchDelete,getPurchaseBatchCount} from "@/api/finance/PurchaseBatch/PurchaseBatch";
import { getStockInsert,getAllStock,getStockid } from "@/api/finance/Stock/Stock";
import { listData } from "@/api/system/dict/data" 
import { getToken } from "@/utils/auth";
export default {
  inheritAttrs: false,
  components: {},
  props: [],
  data() {
    return {
      // 按钮可用
      editBotton:true,
      deleteBotton:true,
      drawer:false,
      // 表格数据
      tableData:[],
      // 采购员数据
      purchaserDict:[],
      countNum:0,
      restaurants:[],
      restaurants1:[],
      restaurants3:[],
      restaurants5:[],
      restaurants6:[],
      restaurants7:[],
      queryParams:{
        salesInvoiceNumber:'',
        salesDate:'',
        salesOrderNumber:'',
       
        
        pageSize:10,
        pageNum:1,
        current:1,
      },
      formData: {
        mobile: '',
        field102: undefined,
        field103: false,
        field108: null,
        field107: undefined,
      },
      // 添加
      form: {
          salesOrderNumber:undefined,
          salesDeliveryDate:undefined,
          salesDate:undefined,
          customerName:undefined,
          salesInvoiceNumber:undefined,
          salesInvoiceDate:undefined,
          salesInvoiceQuantity:undefined,
          salesInvoiceAmount:undefined,
          unpaidSalesInvoiceAmount:undefined,
          salesCost:undefined,
          remarks:undefined,
          createSource: this.$store.state.user.name,
          updateUser: this.$store.state.user.name
        },

      editform:{
        salesOrderNumber:undefined,
          salesDeliveryDate:undefined,
          salesDate:undefined,
          customerName:undefined,
          salesInvoiceNumber:undefined,
          salesInvoiceDate:undefined,
          salesInvoiceQuantity:undefined,
          salesInvoiceAmount:undefined,
          unpaidSalesInvoiceAmount:undefined,
          salesCost:undefined,
          remarks:undefined,
          updateUser: this.$store.state.user.name
      },
      stock:{
        productName:undefined,
        model:undefined,
        stockQuantity:undefined,
        unit:undefined,

      },
      rules: {
      
        salesOrderNumber:[ { required: true, message: '请选择采购批次', trigger: 'change' },],
        salesDeliveryDate:[ { required: true, message: '请输入货物信息', trigger: 'change' },],
        salesDate:[ { required: true, message: '请输入数量', trigger: 'change' },],
        customerName:[ { required: true, message: '请输入订货号', trigger: 'change' },],
        salesInvoiceNumber:[ { required: true, message: '请输入', trigger: 'change' },],
        salesInvoiceDate:[ { required: true, message: '请输入', trigger: 'change' },],
        salesInvoiceQuantity:[ { required: true, message: '请输入', trigger: 'change' },],
        salesInvoiceAmount:[ { required: true, message: '请输入', trigger: 'change' },],
        unpaidSalesInvoiceAmount:[ { required: true, message: '请输入', trigger: 'change' },],
        salesCost:[ { required: true, message: '请输入', trigger: 'change' },],
        remarks:[ { required: true, message: '请输入', trigger: 'change' },],
        

        // mobile: [{
        //   required: true,
        //   message: '请输入手机号',
        //   trigger: 'blur'
        // }, {
        //   pattern: /^1(3|4|5|7|8|9)\d{9}$/,
        //   message: '手机号格式错误',
        //   trigger: 'blur'
        // }],
        
        // field108: [{
        //   required: true,
        //   message: '请选择日期选择',
        //   trigger: 'change'
        // }],
      },

      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/finance/kltSalesOrder/importData"
      },
      pickerOptionsdate: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value1: '',
        field102Options:{},
        dialogTableVisible: false,
        // 页面
        addHanderPop: false,
        editHanderPop: false,
        uploadOpen:false,

        value2:'',
        formLabelWidth: '120px',
        // 下拉框数据
        queryFrom1:[],
        queryFrom2:[],
        //删除数据的id
        delIds:[]
    }
  },
  mounted() {
      this.restaurants = this.loadAll();
  },
  computed: {},
  watch: {},
  created() {
    //  获取当前时间
    var time = new Date();
    var day = ("0" + time.getDate()).slice(-2);
    var month = ("0" + (time.getMonth() + 1)).slice(-2);
    var today = time.getFullYear() + "-" + month + "-" + day;
    this.form.paymentDate   = today;
    this.form.invoiceDate   = today;
    
    
    getSalesOrderList(this.queryParams).then(response => {
      this.tableData = response.rows;
      this.countNum = response.total;
    });
    
//  拿取字典数据
    const queryParams1= {
        pageNum: undefined,
        pageSize: undefined,
        dictType: 'purchaser',
        dictLabel: undefined,
        status: undefined
      };
    listData(queryParams1).then(response => {
      this.purchaserDict = response.rows;
    });
    
  },
  methods: {
      // handleClose
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
    
      // 修改表单
      editPop(){
        this.editHanderPop=true;
      },



   
  
   
   
    // 添加数据
    addtable(formname){
      console.log(this.form);
      this.$refs[formname].validate((valid) => {
          if (valid) {
            
             getSalesOrderInsert(this.form).then(response => {
              console.log(this.form);
              
              if(response.data==true){
                this.$message({
                  message: '添加成功',
                  type: 'success'
                });
                this.addHanderPop = false;
                clearTimeout(this.timeout);
                this.timeout = setTimeout(() => {
                  this.resetForm();
                }, 500 * Math.random()); 
              }
            });
            
            
            
            getSalesOrderList(this.queryParams).then(response => {
              this.tableData = response.rows;
              this.countNum = response.total;
            }); 
            
          } else {
            this.open3();
          }
        });

       
        
    },
    edittable(formname){
      if(this.editform.purchaseName==''||this.editform.purchaseName==undefined){
        this.editform.purchaseId=undefined
      }
      
      this.$refs[formname].validate((valid) => {
          if (valid) {
            delete formname.createSource;
            getSalesOrderEdit(this.editform).then(response => {
             
              if(response.data==true){
                this.$message({
                  message: '修改成功',
                  type: 'success'
                });
                this.editHanderPop = false;
                clearTimeout(this.timeout);
                this.timeout = setTimeout(() => {
                  this.resetForm();
                }, 500 * Math.random());
              }
            });
            getSalesOrderList(this.queryParams).then(response => {
              this.tableData = response.rows;
              this.countNum = response.total;
            }
            );  
          } else {
            this.open3();
          }

        });
       
    },
    // 筛选下拉数据
    loadAll() {
      return []
    },


    // 订单名称筛选
    querySearchAsync(queryString, cb) {
        var restaurants = this.restaurants;       
        var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;
        clearTimeout(this.timeout);
        this.restaurants=[];
            this.timeout = setTimeout(() => {
              getAllPurchaseBatch().then(response=>{
                response.data.forEach(item=>{
                  this.restaurants.push({value:item.orderName,address:item.orderNumber+"-"+item.purchaser +"-"+item.order_number,id:item.purchaseId})
                });
              })
              cb(results);
            }, 1000 * Math.random());
    },


    // 订单名称筛选
    querySearchAsync1(queryString, cb) {
      var restaurants1 = this.restaurants1;       
        var results = queryString ? restaurants1.filter(this.createStateFilter(queryString)) : restaurants1;
        clearTimeout(this.timeout);
        this.restaurants1=[];
            this.timeout = setTimeout(() => {
              getAllPurchaseBatch().then(response=>{
                response.data.forEach(item=>{
                  this.restaurants1.push({value:item.orderName,address:item.orderNumber+"-"+item.purchaser +"-"+item.order_number,id:item.purchaseId})
                });
              })
              cb(results);
            }, 1000 * Math.random());
    },
    querySearchAsync5(queryString, cb) {
      var restaurants5 = this.restaurants5;       
        var results = queryString ? restaurants5.filter(this.createStateFilter(queryString)) : restaurants5;
        clearTimeout(this.timeout);
        this.restaurants5=[];
            this.timeout = setTimeout(() => {
              getAllSalesOrder().then(response=>{
                response.data.forEach(item=>{
                  this.restaurants5.push({value:item.salesInvoiceNumber,address:"开票数量：" +item.salesInvoiceQuantity})
                });
              })
              cb(results);
            }, 1000 * Math.random());
    },

    // this.restaurants1.push({value:item.model,address:item.productName+"-"+item.stockQuantity+item.unit ,id:item.stockId})
    querySearchAsync3(queryString, cb) {
      var restaurants3 = this.restaurants3;       
        var results = queryString ? restaurants3.filter(this.createStateFilter(queryString)) : restaurants3;
        clearTimeout(this.timeout);
        this.restaurants3=[];
            this.timeout = setTimeout(() => {
              getAllStock().then(response=>{
                response.data.forEach(item=>{
                  this.restaurants3.push({value:item.model,address:item.productName+"-"+item.stockQuantity+item.unit ,id:item.stockId})
                });
              })
              cb(results);
            }, 1000 * Math.random());
    },
    querySearchAsync4(queryString, cb) {
      var restaurants4= this.restaurants4;       
        var results = queryString ? restaurants4.filter(this.createStateFilter(queryString)) : restaurants4;
        clearTimeout(this.timeout);
        this.restaurants4=[];
            this.timeout = setTimeout(() => {
              getAllStock().then(response=>{
                response.data.forEach(item=>{
                  this.restaurants4.push({value:item.model,address:item.productName+"-"+item.stockQuantity+item.unit ,id:item.stockId})
                });
              })
              cb(results);
            }, 1000 * Math.random());
    },
    // 
    querySearchAsync7(queryString, cb) {
        var restaurants7 = this.restaurants7;
        var results1 = queryString ? restaurants7.filter(this.createStateFilter(queryString)) : restaurants7;
    clearTimeout(this.timeout);
    this.restaurants7=[];
        this.timeout = setTimeout(() => {
          getAllSalesOrder().then(response=>{
            response.data.forEach(item=>{
              this.restaurants7.push({value:item.salesOrderNumber,address:item.customerName})
            });
          })
          cb(results1);
        }, 1000 * Math.random());
    },

    createStateFilter(queryString) {
        return (state) => {
          return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
    },


    handleSelect(item) {
        // 选择内容并查询
        this.form.purchaseName = item.value;
        this.form.purchaseId = item.id;
        
    },
    handleSelect2(item) {
        // 选择内容并查询
        this.editform.purchaseName = item.value;
        this.editform.purchaseId = item.id;
    },
    handleSelect5(item) {
        // 选择内容并查询
        this.queryParams.purchaseName = item.value;
        this.queryParams.purchaseId = item.id;
        this.getQueryFrom();
        
    },
    handleSelect3(item) {
        // 选择内容并查询
        this.form.productName = item.value;
        this.form.stockId = item.id;
        
    },
    handleSelect4(item) {
        // 选择内容并查询
        this.editform.productName = item.value;
        this.editform.stockId = item.id;
       
        
    },
    handleSelect6(item) {
        // 选择内容并查询
        this.queryParams.productName = item.value;
        this.queryParams.stockId = item.id;
        this.getQueryFrom();
    },
    handleSelect7(item) {
        // 选择内容并查询
        this.queryParams.orderName = item.value;
        this.getQueryFrom();
    },
    
    // 重置表单
    resetForm(item) {
      if(item==undefined){
        for (let key in this.queryParams) {
            if (this.queryParams.hasOwnProperty(key)) {
              this.queryParams[key] = null; // 或者使用 delete jsonObj[key];
            }
        }

      }else if(item == "purchaseName"){
        this.queryParams.purchaseId = undefined;
      }else if(item == "productName"){
        this.queryParams.stockId = undefined;
      }else if(item == "orderName"){
        this.queryParams.orderName = undefined;
      }else if(item == "orderNumberProduct"){
        this.queryParams.orderNumberProduct = undefined;
      }
      
    for (let key in this.form) {
        if (this.form.hasOwnProperty(key)) {
          this.form[key] = null; 
        }
    }
    for (let key in this.editform) {
        if (this.editform.hasOwnProperty(key)) {
          this.editform[key] = null;
        }
    }
    this.getQueryFrom();
    },
    getQueryFrom(){
      getSalesOrderCount(this.queryParams).then(response => {
        this.countNum = response.data;
      });
      getSalesOrderList(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.countNum = response.total;
      })
    },

    deletetable(){
      let idList  = this.delIds
      idList = JSON.parse(JSON.stringify(idList));
      if(idList.length>0){
        setTimeout(()=>{
        
        getSalesOrderDelete(idList).then(response => {
          if(response.data==true){
            console.log(response.date);
            
            getSalesOrderList(this.queryParams).then(response => {
              this.tableData = response.rows;
              this.countNum = response.total;
            }); 
            this.$message({
              message: '删除成功',
              type: 'success'
            });
          }
      })
      },800)
      }
    },

    handleCurrentChange(val) {
      this.queryParams.pageNum=val;
      console.log(val)
      getSalesOrderList(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.countNum = response.total;
      });
    },
    handleSizeChange(val) {
      this.queryParams.pageSize=val;
      console.log(val)
      getSalesOrderList(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.countNum = response.total;
      });
    },
    getList() {
      this.loading = true;
      getSalesOrderList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },

    open3() {
        this.$message({
          message: '请检查信息是否填写完整',
          type: 'warning'
        });
      },
 
    onOpen() {},
    onClose() {
      this.$refs['elForm'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
    },
    handleConfirm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        this.close()
      })
    },
   

     /** 下载模板操作 */
     importTemplate() {
      this.download('finance/kltSalesOrder/importTemplate', {
      }, `销售批次导入模板_${new Date().getTime()}.xlsx`)
    },

    // 导出数据
    importData() {
      this.download('finance/kltSalesOrder/export', {
          
      }, `销售批次数据导出_${new Date().getTime()}.xlsx`)
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
//  表格多选
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.delIds=[];
        // 判断选择行数
        if(val.length==1){

          this.multipleSelection = val;
        let aa = {
          salesOrderId:val[0].salesOrderId?val[0].salesOrderId:'',
          salesOrderNumber:val[0].salesOrderNumber?val[0].salesOrderNumber:'',
          salesDeliveryDate:val[0].salesDeliveryDate?val[0].salesDeliveryDate:'',
          salesDate:val[0].salesDate?val[0].salesDate:'',
          customerName:val[0].customerName?val[0].customerName:'',
          salesInvoiceNumber:val[0].salesInvoiceNumber?val[0].salesInvoiceNumber:'',
          salesInvoiceDate:val[0].salesInvoiceDate?val[0].salesInvoiceDate:'',
          salesInvoiceQuantity:val[0].salesInvoiceQuantity?val[0].salesInvoiceQuantity:'',
          salesInvoiceAmount:val[0].salesInvoiceAmount?val[0].salesInvoiceAmount:'',
          unpaidSalesInvoiceAmount:val[0].unpaidSalesInvoiceAmount?val[0].unpaidSalesInvoiceAmount:'',
          salesCost:val[0].salesCost?val[0].salesCost:'',
          remarks:val[0].remarks?val[0].remarks:'',
          updateUser: this.$store.state.user.name
          };   
          console.log(val[0].salesOrderId)
          this.delIds.push(val[0].salesOrderId);
          this.editform=aa;
         

          this.editBotton=false;
          this.deleteBotton=false;
        }else if(val.length>0){
          for(let a=0;a<val.length;a++){
            this.delIds.push(val[a].salesOrderId);
          }
          this.editBotton=true;
          this.deleteBotton=false;
        }else{
          this.editBotton=true;
          this.deleteBotton=true;
        }
      },
      addStock(){
        getStockInsert(this.stock).them(response=>{
          if(response.data==true){
            this.$message({
              message: '新增成功',
              type: 'success'
            });
          }
      })
      },
      Changed(){
        this.$forceUpdate()

      }
  }
}

</script>














<style>
.search{
    margin-top: 10px;
}
.infotable{
    margin-top: 10px;
    margin-left: 1%;
    margin-right: 1%;    
}
.infotable_handerchild{
    margin-top: 10px;
    margin-left: 40px;
}
.pagination{
  margin-right: 20px;    
    text-align :right;
}
.HanderPop{
  width:100%;
  display: inline-block;
}
.inputplace{
  width: 200px;
}
li {
    line-height: normal;
    padding: 7px;
    width: 100%;
    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .addr {
      font-size: 12px;
      color: #9b9b9b;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
  .addstore{
    margin-left: 20px;
  }
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>